#pragma once

#include "input.h"							//dip_t is here
#include "list.h"							//list_c is here

#define MAX_ROMS			32
#define MAX_INPUTPORTS	6

#define ROTATE_0			0
#define ROTATE_90			1
#define ROTATE_180		2
#define ROTATE_270		3

//input button flags
#define I_HIGH				0x01
#define I_LOW				0x02

#define I_NMI				0x10
#define I_IRQ				0x20
#define I_FIRQ				0x40

#define I_CPU_NMI(n)		(((n) << 8) | (I_NMI))
#define I_CPU_IRQ(n)		(((n) << 8) | (I_IRQ))
#define I_CPU_FIRQ(n)	(((n) << 8) | (I_FIRQ))

/*
struct contains information about one key
*/
typedef struct InputButton_s
	{
	char Name[32];					//name of button
	u32 InputCode;					//internal code for keypress (ex. I_UP, I2_DOWN, I_COIN1, etc)
	u8 Bit;							//bit that represents this button
	u32 Flags;						//flags for this button
	} InputButton;

/*
struct contains information about one input port.

port can be used for input, it holds eight 
configurable bits.
*/
typedef struct InputPort_s
	{
//	u32 Num;							//number to map this port to (from 1 to MAX_INPUTPORTS, 0 = end)
//	u32 Flags;						//port flags
	InputButton Buttons[8];		//buttons contained in port
	} InputPort;

class CMachine;
class CRom;
class CRomSet
{
private:
	char Path[512];
	char Name[32];
	u32 Flags;
	dip_t *Dip[8];										//dip switch setting pts
	highscore_t *HighScoreInfo;					//high score save/load information
	InputPort *InputPorts[MAX_INPUTPORTS];		//input port information
	int w,h;												//screen dimensions
	int Rotate;											//screen rotation
protected:
	list_c Roms;										//roms included in this set
protected:
	int AddROM(char *fn,u32 a,u32 s,u32 c,u32 f);	//add rom to romset
	int DupROM(u32 a,u32 s = 0);							//duplicate rom
public:
	CRomSet(char *n = "");							//n = name of romset
	virtual ~CRomSet();
	virtual CRom *GetROM(int idx);				//get rom from index
	virtual int Num();								//returns number of roms in romset
	void SetName(char *n);							//set romset name
	char *GetName(){return(Name);}
	void SetFlags(u32 f);
	u32 GetFlags();
	int Load(char *path);							//load romset from path
	int LoadZIP(char *filename);					//load romset from zip
	void Unload();										//unload romset
	virtual CMachine *CreateMachine() = 0;		//create machine used by romset
	void InitDip();
	void SetDip(int n,dip_t *d);					//set dip switch
	void SetPort(int n,InputPort *d);			//set input port
	dip_t *GetDip(int n);							//get dip switch
	InputPort *GetPort(int n);						//get input port
	void SetHighScoreInfo(highscore_t *h);		//set high score information
	highscore_t *GetHighScoreInfo();				//get high score information
	void SetScreen(int ww,int hh,int rr = ROTATE_0){w=ww;h=hh;Rotate=rr;}
	int ScreenW()
		{
		if(Rotate == ROTATE_90 || Rotate == ROTATE_270)
			return(h);
		return(w);
		}
	int ScreenH()
		{
		if(Rotate == ROTATE_90 || Rotate == ROTATE_270)
			return(w);
		return(h);
		}
	int GetRotate(){return(Rotate);}
};

#include "Rom.h"
#include "Machine.h"
